#include "settlement_type.h"


using namespace std;


map<string, shared_ptr<SettlementType>> SettlementType::idsMap;

vector<shared_ptr<SettlementType>> SettlementType::cities;
vector<shared_ptr<SettlementType>> SettlementType::castles;


void SettlementType::add(shared_ptr<SettlementType> settlementType)
{
	idsMap[settlementType->id] = settlementType;

	if (settlementType->isCastle)
	{
		settlementType->level = castles.size();
		castles.push_back(settlementType);
	}
	else
	{
		settlementType->level = cities.size();
		cities.push_back(settlementType);
	}
}


shared_ptr<SettlementType> SettlementType::get(string id)
{
	shared_ptr<SettlementType> settlementType;

	map<string, shared_ptr<SettlementType>>::iterator i;
	i = idsMap.find(id);
	if (i != idsMap.end())
	{
		settlementType = i->second;
	}

	return settlementType;
}
